package com.pwt.controller.basicsetting;

import com.pwt.annotation.Update;
import com.pwt.common.ResultPage;
import com.pwt.entity.JobNo;
import com.pwt.model.ComboBoxModel;
import com.pwt.service.JobNoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @date 2022/1/20 11:14
 * @Description
 */
@RestController
@Tag(name = "云之家消息配置")
public class JobNoController {

    private JobNoService jobNoService;

    public JobNoController(JobNoService jobNoService) {
        this.jobNoService = jobNoService;
    }

    @GetMapping("/jobNos")
    @Operation(description = "分页查询 云之家消息发送配置",summary = "分页查询 云之家消息发送配置")
    @Parameters({
            @Parameter(name = "page",description = "当前页",required = true),
            @Parameter(name = "limit",description = "每页展示数",required = true),
            @Parameter(name = "type",description = "警报类型，1-控制限，2-上下限",required = false),
            @Parameter(name = "jobNumber",description = "工号",required = false)
    })
    public ResultPage<JobNo> queryJobNoPage(Integer page, Integer limit,@RequestParam(required = false) Integer type,@RequestParam(required = false) String jobNumber){
        return this.jobNoService.queryJobNoPage( page,  limit,  type,  jobNumber);
    }

    @PostMapping("jobNo")
    @Operation(summary = "新增消息配置",description = "新增消息配置")
    public JobNo insertJobNo(@RequestBody JobNo jobNo){
        return this.jobNoService.updateJobNo(jobNo);
    }


    @PutMapping("jobNo")
    @Operation(summary = "修改消息配置",description = "修改消息配置")
    public JobNo updateJobNo(@RequestBody @Validated(value = Update.class) JobNo jobNo){
        return this.jobNoService.updateJobNo(jobNo);
    }


    @GetMapping("user-jobNos")
    @Operation(summary = "查询所有用户和工号",description = "查询所有用户和工号")
    public List<ComboBoxModel> queryAllUserJobNo(){
        return this.jobNoService.queryUserJobNo();
    }

}
